/**
 * Author zdc
 * 程序主入口
 */
/*if(!window.opener){
	alert("请登录!");
	location.href="about:blank";
}*/
$(function() {
	Global.userid= getUrlParameter("user-id");
	Global.language=getUrlParameter("request-locale");
	if (Global.userid){
		getRights();
		initTabEvt();
	}else{
		alert("请登录!");
		location.href="about:blank";
	}
});

function getRights(uesrId){
	//获取权限
	showLoading();
	$.ajax({
		type:'get',
		url:"./services/userservice",//
		data:{
			usereid:Global.userid
		},
		dataType:'json',
		success:function(response){
			if(!response||response=="null"){
				alert("无权限!");
				location.href="about:blank";
				return;
			}
			Global.mmRights=response.OtherMMs;//管理的MM集合
			getCityRights();
		},
		error:function(response){
			console.log("获取权限出错");
			hideLoading();
		}
	});
}

function getCityRights(){
	var mms = "'"+Global.mmRights.join("','")+"'";
	$.ajax({
		type:'post',
		url:'./services/queryservice/city',
		data:{
			mms:mms
		},
		dataType:'json',
		success:function(response){
			Global.cityRights=response;
			initWidget();
			hideLoading();
		},
		error:function(response){
			console.log("获取market出错");
			hideLoading();
		}
	});
}

function initWidget(){
    var loction  = dojo.query(".body_cityreport")[0];
    require(["widgets/planningModule/cityReportWidget/CityReportWidget"],function(CityReportWidget){
    	Global.cityReport = new CityReportWidget();
    	Global.cityReport.startup();
    	Global.cityReport.placeAt(loction);
    });
    
    var mappingreportTab = dojo.query(".body_mappingreport")[0];
    require(["widgets/planningModule/mappingReportWidget/MappingReportWidget"],function(MappingReportWidget){
        Global.mappingReportWidget = new MappingReportWidget();
        Global.mappingReportWidget.startup();
        Global.mappingReportWidget.placeAt(mappingreportTab);
    });
    slideCtrl();
}

function initTabEvt() {
    $('.pmt-content-tabs > li').bind('click',getSelectPPItem);
}

// 点击Tab切换

function getSelectPPItem(evt){
    var curTarget = evt.target; 
    if($(curTarget).hasClass("active")) return;
    
    $(curTarget).siblings().removeClass("active");
    $(curTarget).addClass("active");
    
    $(".tab-content > div").removeClass("active");
    $(curTarget.getAttribute("data-bind")).addClass("active");  
} 

//esri.config.defaults.io.errorHandler=function(){console.log(arguments)}